// 查询列表
import request from "@/utils/request";

/**
 * 查询省市区
 * @returns {Promise<*[]>}
 */
export function districtOptionSelect() {
    return TreeDistrict().then( response => {
        return districtOptionData(response.data);
    })

}

/**
 * 转换为 关联数据
 * @param data
 * @returns {*[]}
 */
function districtOptionData(data){
    let options=[];
    for(let idx in data){
        let obj={value:data[idx].adCode,label:data[idx].adName};
        let objChildren= data[idx].pubDistricts;
        if(!! objChildren){
            let child=districtOptionData(objChildren)
            if(!!child){
                obj.children=child;
            }

        }
        options.push(obj);
    }
    return options;
}

export function TreeDistrict() {
    return request({
        url: '/wbzj-biz/district/getDistrictStrucList',
        method: 'get'
    })
}
